import logging
import os
import random
import time
#
# import pyautogui as pag
#
# import pydirectinput as pdg
import src.configs
from src.mouse_key import *
from src.configs import IMAGE_PATH


# 屏幕大小
# size = pag.size()
# print(size)

def click_btn():
    # 按钮图标
    btn = "images/version_btn.png"
    # 获取屏幕尺寸
    size = pag.size()
    logging.info(f"屏幕大小：{size}")
    pag.moveTo(size.width / 2, size.height / 2, duration=2)
    # get_and_click(btn)


def copy_and_paste():
    pag.dragRel(0, 100)
    pag.hotkey('ctrl', 'c')
    pag.moveTo(300, 300)
    pag.click()
    pag.hotkey('ctrl', 'v')


def count_time():
    duration = random.randint(14, 59)
    for i in reversed(list(range(duration))):
        print(f"时间：{i}")
        time.sleep(1)


def auto_start():
    running = False
    try:
        pos = get_item_pos(os.path.join(IMAGE_PATH, "interface", "consumption_item.png"))
        running = True
    except Exception as e:
        print("报错：", e)
        print("游戏未启动")
    if not running:
        icon_path = os.path.join(IMAGE_PATH, "interface", "icon.png")
        launch_path = os.path.join(IMAGE_PATH, "interface", "launch_game.png")
        acknowledge_box_path = os.path.join(IMAGE_PATH, "interface", "acknowledge_box.png")
        agree_path = os.path.join(IMAGE_PATH, "interface", "agree.png")
        account_path = os.path.join(IMAGE_PATH, "interface", "account.png")
        password_path = os.path.join(IMAGE_PATH, "interface", "password.png")
        login_path = os.path.join(IMAGE_PATH, "interface", "login.png")

        x, y = locate_click(icon_path)
        time.sleep(1)
        pag.mouseDown(button="right")
        pag.mouseUp(button="right")
        # click("right")
        pdg.moveTo(x + 8, y + 8)
        click("left")
        count_down(5)
        locate_click(launch_path)
        count_down(20)
        point_screen()
        locate_click(acknowledge_box_path)
        time.sleep(1)
        locate_click(agree_path)

        locate_click(account_path)
        pdg.press(list("13503032742"))
        # pdg.press(list("13728722742"))
        point_screen()
        time.sleep(2)
        locate_click(password_path)
        pdg.press(list("cqwhlove1"))
        point_screen()
        time.sleep(1)
        locate_click(login_path)
        time.sleep(20)
        # 第一个人：(390, 838)
        # 第二个人：(703, 838)
        # 第三个人：(1034, 838)
        pdg.moveTo(390, 838)
        # double_click()


def change_skill():
    time.sleep(3)
    pdg.moveTo(300, 300)
    pdg.click()
    keys = ["f1", "f2", "f3", "f4"]
    key_idx = 0
    while True:
        key = keys[key_idx]
        pdg.press(key)
        print(f"当前Key:{key}")
        count_time()
        if key_idx < len(keys) - 1:
            key_idx += 1
        else:
            key_idx = 0


if __name__ == "__main__":
    # move_mouse()
    # click_btn()
    # drag_mouse()
    # scroll()
    # copy_and_paste()
    # change_skill()
    auto_start()
